package threading;
//在类内部把实例创建好，同时禁止外部重新创建实例
class Singleton{
    //唯一实例的本体
    private static Singleton instance = new Singleton();
    //获取到实例的方法
    public static Singleton getInstance(){
        return instance;
    }
    //禁止外部new实例
    private  Singleton(){

    }

}
public class ThreadDemo15 {
    public static void main(String[] args) {
        //此时 s1 和 s2 是同一个对象！！
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        //Singleton s3 = new Singleton();
    }
}
